package com.lgcns.andteam2.todaymenu.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

/**
 * SQLiteOpenHelper를 상속받아 DB 초기화/업데이트 작업을 수행.
 */
public class MenuDBHelper extends SQLiteOpenHelper {
    private static final String TAG = MenuDBHelper.class.getSimpleName();
    // SQLite DB 파일명
    public static String DB_FILENAME = "menu.db";

    private static String CREATE_TB_PLACE = 
        "CREATE TABLE TB_PLACE ( \n" +
        "  _id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, \n" +
        "  place TEXT)";

    private static String CREATE_TB_DIETITIAN = 
        "CREATE TABLE TB_DIETITIAN ( \n" +
        "  _id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, \n" +
        "  place_id INTEGER, \n" +
        "  dietitian_name TEXT, \n" +
        "  email TEXT)";

    private static String CREATE_TB_MENU = 
        "CREATE TABLE TB_MENU ( \n" +
        "  _id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, \n" +
        "  place_id INTEGER, \n" +
        "  menu_date TEXT, \n" +
        "  menu_day TEXT, \n" +
        "  gubun_code TEXT, \n" +
        "  gubun TEXT, \n" +
        "  corner TEXT, \n" +
        "  menu_name TEXT, \n" +
        "  cal INTEGER, \n" +
        "  side_menu_01 TEXT, \n" +
        "  side_menu_02 TEXT, \n" +
        "  side_menu_03 TEXT, \n" +
        "  side_menu_04 TEXT, \n" +
        "  side_menu_05 TEXT, \n" +
        "  side_menu_06 TEXT, \n" +
        "  side_menu_07 TEXT, \n" +
        "  dessert TEXT)";

    public MenuDBHelper(Context context) {
        super(context, DB_FILENAME, null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        Log.d(TAG, "onCreate()");
//        db.execSQL(CREATE_TB_PLACE);
//        db.execSQL(CREATE_TB_DIETITIAN);
//        db.execSQL(CREATE_TB_MENU);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.d(TAG, "onUpgrade(oldVersion : " + oldVersion + ", newVersion : " + newVersion + ")");
//        db.execSQL("DROP TABLE IF EXISTS TB_PLACE");
//        db.execSQL("DROP TABLE IF EXISTS TB_DIETITIAN");
//        db.execSQL("DROP TABLE IF EXISTS TB_MENU");
//        
//        onCreate(db);
    }
}